package com.yanze.schoolinformation.adapter.rv;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import com.yanze.schoolinformation.R;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewAdapter;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewHolder;
import com.yanze.schoolinformation.databinding.ItemSchoolNewsBinding;
import com.yanze.schoolinformation.app.C;
import com.yanze.schoolinformation.model.bean.SchoolNewsBean;
import com.yanze.schoolinformation.utils.PerfectClickListener;
import com.yanze.schoolinformation.view.webview.WebViewActivity;

/**
 * Created by MrZheng on 2018/4/28.
 */

public class SchoolNewsAdapter extends BaseRecyclerViewAdapter<SchoolNewsBean> {

    @NonNull
    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(parent, R.layout.item_school_news);
    }

    private class ViewHolder extends BaseRecyclerViewHolder<SchoolNewsBean, ItemSchoolNewsBinding> {

        public ViewHolder(ViewGroup viewGroup, int layoutId) {
            super(viewGroup, layoutId);
        }

        @Override
        public void onBindViewHolder(final SchoolNewsBean object, int position) {
            binding.setNews(object);
            binding.executePendingBindings();

            binding.rlSchoolNews.setOnClickListener(new PerfectClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    WebViewActivity.loadUrl(v.getContext(), C.url.XuHaiUrl + object.getHref(), object.getTitle());
                }
            });
        }
    }
}
